package com.gywj.race.wxPay;

import java.io.*;
import java.net.URISyntaxException;

public class MyWxPayConfig extends WXPayConfig {
    public static final String TRADETYPE = "JSAPI";
    private byte[] certData;
    private String notifyUrl = "https://www.geyuewujiang.com/participant/wxpay/notice";
    private String secret;

    public MyWxPayConfig() throws IOException, URISyntaxException {
        //从微信商户平台下载的安全证书存放的目录
        String certPath = this.getClass().getResource("/").toURI().getPath()+"apiclient_cert.p12";
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    @Override
    public String getAppID() {
        return "wxb662267660c2dbea";
    }
    public String getSecret() {
        return "8a122fccb15078796adb3a7d489607cb";
    }


    @Override
    public String getMchID() {
        return "1601011787";
    }
    @Override
    public String getKey() {
        return "8a122fccb15078796adb3a7d489607cc";
    }


    public void setSecret(String secret) {
        this.secret = secret;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    @Override
    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    @Override
    IWXPayDomain getWXPayDomain() {
        return new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {
            }

            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new DomainInfo("api.mch.weixin.qq.com", false);
            }
        };
    }
}